package com.getpebble.android.framework.protocol;

import java.util.HashMap;
import java.util.Map;

public enum EndpointId {
    FIRMWARE(1),
    TIME(11),
    VERSIONS(16),
    PHONE_VERSION(17),
    SYSTEM_MESSAGE(18),
    MUSIC_CONTROL(32),
    PHONE_CONTROL(33),
    APP_MESSAGE(48),
    APP_LIFECYCLE(49),
    APP_CUSTOMIZE(50),
    LOGS(2000),
    PING(2001),
    LOG_DUMP(2002),
    RESET(2003),
    APP(2004),
    MFG(2004),
    APP_LOGS(2006),
    NOTIFICATION(3000),
    EXTENSIBLE_NOTIFICATION(3010),
    RESOURCE(4000),
    SYS_REG(5000),
    FCT_REG(5001),
    APP_INSTALL_MANAGER(6000),
    RUNKEEPER(7000),
    PUT_BYTES(48879),
    DATA_LOG(6778),
    SCREENSHOT(8000),
    CORE_DUMP(9000),
    FILE_INSTALL_MANAGER(8181),
    MAX_ENDPOINT(65535),
    INVALID_ENDPOINT(-1);
    
    private static final Map<Integer, EndpointId> intToTypeMap = null;
    private final int code;

    static {
        intToTypeMap = new HashMap();
        for (EndpointId type : values()) {
            intToTypeMap.put(Integer.valueOf(type.code), type);
        }
    }

    private EndpointId(int code) {
        this.code = code;
    }

    public static EndpointId fromCode(short code) {
        EndpointId endpointId = (EndpointId) intToTypeMap.get(Integer.valueOf(65535 & code));
        if (endpointId == null) {
            return INVALID_ENDPOINT;
        }
        return endpointId;
    }

    public short getCode() {
        return (short) (this.code & 65535);
    }
}
